<?php

session_start();

if($_SESSION['name']){
	header('Location: index.php');
	die;
}

if (isset($_POST['submit'])){
	include './source/class/class_core.php';
	
	$name = trim($_POST['name']);
	$pwd = trim($_POST['pwd']);
	
	if($name == '' || $pwd == ''){
		echo "<script>alert('提示：用户和密码不能为空！');</script>";
	} elseif ( DB::result_first("SELECT id FROM `om_user` WHERE `name` = '$name'") ){
		echo "<script>alert('提示：该用户名已经存在了！');</script>";
	} else {
		$data = array('name' => $name, 'pwd' => $pwd, 'register_time' => time());
		if ( DB::insert('user', $data) ){
			echo "<script>alert('提示：注册成功！');window.location='login.php';</script>";
		} else {
			echo "<script>alert('提示：注册失败，请与管理员联系！');</script>";
		}
	}
}



?>
<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>注册</title>
	<link rel="stylesheet" href="images/global.min.css">
</head>
<body id="login">
    <div id="header">
        欢迎加入木桶饭协会(YY群：6550976)，会长：MM不乖哦(YY号：909010484)
    </div>
    <form method="post" id="form">
        <h1>木桶饭协会会员注册，输入用户名和密码进行注册：</h1>
        <input type="text" name="name" class="name" />
        <input type="password" name="pwd" class="pwd" />
        <button type="submit" name="submit">用户注册</button>
        <a href="login.php" title="">会员请点进登录页面，登录后订餐！</a>
    </form>
<!-- 偷窥代码狂就是你，还看，就是你！ -->